package com.szrt.day20170506.ch01;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerSocketTest {
	
	
	
	public static void main(String[] args)  throws Exception{
		
		
		//1 在指定端口上生成ServerSocket
		ServerSocket  ss = new ServerSocket(8888);
		
		//2 侦听客户端发来的请求  阻塞   until  目前不干活  直到 有客户端发请求过来
		Socket socket = ss.accept();
		
		//3收消息
		InputStream is = socket.getInputStream();
		
		
		
		byte[] b = new byte[1024];
		
		
		while(is.read(b) != -1){
			String string  = new String(b,0,b.length);
			System.out.print(string);
		}
		
		is.close();
		socket.close();
		ss.close();
		//io
		
		
		

	}

}
